//
//  HXDVisitorTableViewController.swift
//  weibo
//
//  Created by huxuedong on 15/12/5.
//  Copyright © 2015年 huxuedong. All rights reserved.
//

import UIKit

class HXDVisitorTableViewController: UITableViewController {

    //判断用户是否登录
    var userLogin = HXDUserAccountViewModel.shareInstance.accessToken != nil
    var visitorView: HXDVisitorView?
    
    override func loadView() {
        //根据用户是否登录判断需要加载的视图
        userLogin ? super.loadView() : setupVisitorView()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    private func setupVisitorView() {
        //初始化visitorView视图
        visitorView = HXDVisitorView()
        visitorView?.registerButton.addTarget(self, action: "login", forControlEvents: .TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "login", forControlEvents: .TouchUpInside)
        //将view设置为visitorView视图
        view = visitorView
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "login")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "login")
    }
    
    @objc private func login() {
        let webLoginViewController = HXDWebLoginViewController()
        presentViewController(HXDNavigationController(rootViewController: webLoginViewController), animated: true, completion: nil)
    }

}
